<template>
  <nav class="site-navbar" :class="'site-navbar--' + navbarLayoutType">
    <div class="site-navbar__header">
      <h1 class="site-navbar__brand" @click="$router.push({ name: 'home' })">
        <a class="site-navbar__brand-lg" href="javascript:;">{{entryName}}</a>        <a class="site-navbar__brand-mini" href="javascript:;">
			<img src="~@/assets/img/avatar.png" style="width: 25px;border-radius: 50%;">
		</a>
      </h1>
    </div>
    <div class="site-navbar__body clearfix">
      <el-menu
        class="site-navbar__menu"
        mode="horizontal">
        <el-menu-item class="site-navbar__switch" index="0" @click="sidebarFold = !sidebarFold">
          <icon-svg name="zhedie"></icon-svg>
        </el-menu-item>
      </el-menu>
      <el-menu
        class="site-navbar__menu site-navbar__menu--right"
        mode="horizontal">
        <!-- <el-menu-item index="1" @click="$router.push({ name: 'theme' })">
          <template slot="title">
            <el-badge value="new">
              <icon-svg name="shezhi" class="el-icon-setting"></icon-svg>
            </el-badge>
          </template>
        </el-menu-item> -->
        <el-menu-item class="site-navbar__avatar" index="3">
          <el-dropdown :show-timeout="0" placement="bottom">
            <span class="el-dropdown-link">
              <img src="~@/assets/img/avatar.png" :alt="userName">{{ userName }}
            </span>
            <el-dropdown-menu slot="dropdown">
              <!-- <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item> -->
              <el-dropdown-item @click.native="logoutHandle()">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-menu-item>
      </el-menu>
    </div>
    <!-- 弹窗, 修改密码 -->
    <update-password v-if="updatePassowrdVisible" ref="updatePassowrd"></update-password>
  </nav>
</template>

<script>
  import UpdatePassword from './main-navbar-update-password'
  import { clearLoginInfo } from '@/utils'
  import { entryName } from '@/utils/httpRequest'
  export default {
    data () {
      return {
        updatePassowrdVisible: false,
				chatNumJjqz:0,
				errCount1: 0,
				chatNum1: 0,
        entryName:'',

        numberDtx:0,
        numberDrz:0,
        numberDts:0,
        numberDtg:0,
      }
    },
    components: {
      UpdatePassword
    },
    computed: {
      navbarLayoutType: {
        get () { return this.$store.state.common.navbarLayoutType }
      },
      sidebarFold: {
        get () { return this.$store.state.common.sidebarFold },
        set (val) { this.$store.commit('common/updateSidebarFold', val) }
      },
      mainTabs: {
        get () { return this.$store.state.common.mainTabs },
        set (val) { this.$store.commit('common/updateMainTabs', val) }
      },
      userName: {
        get () { return this.$store.state.user.name }
      }
    },
    methods: {
      // 修改密码
      updatePasswordHandle () {
        this.updatePassowrdVisible = true
        this.$nextTick(() => {
          this.$refs.updatePassowrd.init()
        })
      },
      // 退出
      logoutHandle () {
        this.$confirm(`确定进行[退出]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/sys/logout'),
            method: 'post',
            data: this.$http.adornData()
          }).then(({data}) => {
            if (data && data.code === 0) {
				sessionStorage.clear()
                clearLoginInfo()
				this.$cookie.set('token','')
				this.$cookie.set('numberJjqz', '')
              this.$router.push({ name: 'login' })
            }
          })
        }).catch(() => {})
      },
			// 获取紧急求助待审核数据
			dataSelectJjqz() {
				var _this = this
				this.$http({
					url: this.$http.adornUrl('message/selectMessageCount'),
					method: 'get',
					params: this.$http.adornParams({
						'state': 9,
					})
				}).then(({
					data
				}) => {
					if (data.data>=0) {
						this.$cookie.set('numberJjqz', data.data)
						if (this.errCount1 != data.data) {
							if (data.data > this.errCount1) {
								this.$notify.info({
									title: '消息',
									dangerouslyUseHTMLString: true,
									message: '有' + data.data + '条紧急求助，请前往查看。',
									offset: 80,
									duration: 0,
									type: "warning",
									onClose() {
										_this.updatesD5(1);
									}
								});
							}
							this.errCount1 = data.data
							this.chatNum1 = data.data
						}
					}else {
							this.errCount1 = 0
							this.chatNum1 = 0
						}
				})
			},
			updatesD5(index) {
				this.$router.push({
					path: '/emergencyHelp',
					query: {
						types: index
					}
				})
			},
      // 获取 待提现 数据
      dataSelectDtx() {
      	this.$http({
      		url: this.$http.adornUrl('cash/selectAdminHelpProfit'),
      		method: 'get',
      		params: this.$http.adornParams({
      			'page': 1,
      			'limit': 10,
      			'zhifubaoName': '',
      			'zhifubao': '',
      			'startTime': '',
      			'endTime': '',
      			'phone': '',
      			'classify': '',
            'userType':'',
            'userName':'',
            'orderNumber':'',
            'state': 0,
      		})
      	}).then(({
      		data
      	}) => {
          if (data && data.code === 0) {
          	this.$cookie.set('numberDtx', data.data.total)
          }
      	})
      },
      // 获取 待认证 数据
      dataSelectDrz() {
      	this.$http({
      		url: this.$http.adornUrl('adminerrand/findAllCertification'),
      		method: 'get',
      		params: this.$http.adornParams({
      			'page': 1,
      			'limit': 10,
      			'phone': '',
      			'nickName': '',
            'checkCertification':0,
      		})
      	}).then(({
      		data
      	}) => {
          if (data && data.code === 0) {
          	this.$cookie.set('numberDrz', data.data.totalCount)
          }
      	})
      },
      // 获取 待投诉 数据
      dataSelectDts() {
        // 待审核
      	this.$http({
      		url: this.$http.adornUrl('adminerrand/findAllAppeal'),
      		method: 'get',
      		params: this.$http.adornParams({
      			'page': 1,
      			'limit': 10,
      			'indentNumber': '',
      			'illegalId': '',
            'cityId':'',
            'complaintState':5,
      		})
      	}).then(({
      		data
      	}) => {
          if (data && data.code === 0) {
          	this.$cookie.set('numberDts', data.data.total)
          }
      	})
        // 待申诉
        this.$http({
        	url: this.$http.adornUrl('adminerrand/findAllAppeal'),
        	method: 'get',
        	params: this.$http.adornParams({
        		'page': 1,
        		'limit': 10,
        		'indentNumber': '',
        		'illegalId': '',
            'cityId':'',
            'complaintState':2,
        	})
        }).then(({
        	data
        }) => {
          if (data && data.code === 0) {
          	this.$cookie.set('numberDss', data.data.total)
          }
        })
      },
      // 获取 待推广 数据
      dataSelectDtg() {
      	this.$http({
      		url: this.$http.adornUrl('admin/userExtension/getExtensionList'),
      		method: 'get',
      		params: this.$http.adornParams({
      			'page': 1,
      			'limit': 10,
      			'realName': '',
      			'phone': '',
            'status':1,
      		})
      	}).then(({
      		data
      	}) => {
          if (data && data.code === 0) {
          	this.$cookie.set('numberDtg', data.data.total)
          }
      	})
      },
    },
		mounted() {
      this.entryName = entryName
			this.dataSelectJjqz()
		},
		created() {

			this.chatNumJjqz = setInterval(() => {
				this.dataSelectJjqz()
			}, 6000)
			this.numberDtx = setInterval(() => {
				this.dataSelectDtx()
			}, 6000)
			this.numberDrz = setInterval(() => {
				this.dataSelectDrz()
			}, 6000)

			this.numberDts = setInterval(() => {
				this.dataSelectDts()
			}, 6000)
			this.numberDtg = setInterval(() => {
				this.dataSelectDtg()
			}, 6000)
		},
		beforeDestroy() {
			clearInterval(this.chatNumJjqz)
		}
  }
</script>
